﻿<UserControl x:Class="DirectoryAnalyzer.Controls.FileAnalyzer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             mc:Ignorable="d" MinWidth="600"
             d:DesignHeight="300" d:DesignWidth="800">

    <Grid Name="MainLayout">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="360" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid Name="grdBasePath" Grid.ColumnSpan="3" Margin="5,5,5,2.5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <CheckBox Content="Path: " Margin="0,0,2.5,0" VerticalAlignment="Center" IsChecked="{Binding AutoLoad, Mode=TwoWay}" />
            <Border Name="brdBasePath" Grid.Column="1" Margin="2.5,0" BorderBrush="{Binding ValidationColour}" BorderThickness="1">
                <TextBox Name="txtBasePath" HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                         Text="{Binding BasePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </Border>
            <Button Grid.Column="2" Margin="2.5,0,0,0" Padding="15,2"
                    Content="Load" IsEnabled="{Binding CanLoadFiles}"
                    Command="{Binding LoadFilesCommand}" CommandParameter="{Binding Path=Text, ElementName=txtBasePath}"/>
        </Grid>

        <StackPanel Name="stkFilter" Grid.Row="1" HorizontalAlignment="Left" Orientation="Horizontal">
            <Label Name="lblFilter" Margin="5,0,2.5,0" Content="Filters: " VerticalAlignment="Center" />
            <CheckBox Name="chkAscending" Margin="2.5,0" IsChecked="{Binding IsAscending, Mode=TwoWay}" />
            <ComboBox Name="cmbFilter" Width="100" Margin="2.5,0" VerticalAlignment="Center" 
                      ItemsSource="{Binding AllFilters}" SelectedValuePath="Key" DisplayMemberPath="Value"
                      SelectedIndex="-1" SelectedValue="{Binding SelectedFilter, Mode=TwoWay}" />
            <TextBlock Name="RKD" Width="20" Text="{Binding ElementName=lstExtn, Path=ActualWidth}" />
        </StackPanel>
        <ScrollViewer Name="scrlvExtn" Grid.Row="2" Margin="5,2.5,2.5,2.5" MinWidth="200" 
                      HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
            <ListBox Name="lstExtn" ItemsSource="{Binding AllHierarchicalData}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Name="chkExtn" Margin="5,2.5" IsChecked="{Binding IsSelected, Mode=TwoWay}" 
                                  Command="{Binding DataContext.ExtnSelectionChangeCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" 
                                  CommandParameter="{Binding }">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="200" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Name="txtbExtn">
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="Name:&#x09; {0}">
                                                <Binding Path="ExtnName" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                </TextBlock>
                                <TextBlock Name="txtbSize" Grid.Column="1">
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="Size:&#x09; {0}">
                                                <Binding Path="TotSize" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                </TextBlock>
                            </Grid>
                        </CheckBox>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>

        <GridSplitter Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Width="5" />

        <ScrollViewer Name="scrlvHierData" Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Margin="2.5,2.5,5,2.5"
                      HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <ItemsControl Name="itmctrlHierData" ItemsSource="{Binding AllHierarchicalData_Filtered}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Expander Name="expHierData" IsExpanded="{Binding IsExpanded, Mode=TwoWay}">
                            <Expander.Header>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="200" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Name="txtbExtn">
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="Name:&#x09; {0}">
                                                <Binding Path="ExtnName" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                    <TextBlock Name="txtbSize" Grid.Column="1">
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="Size:&#x09; {0}">
                                                <Binding Path="TotSize" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </Grid>
                            </Expander.Header>
                            <Border Margin="20,2,2,2" MaxHeight="100" BorderBrush="Gray" BorderThickness="1" CornerRadius="3">
                                <ScrollViewer>
                                    <ItemsControl Name="itmcrtlFiles" ItemsSource="{Binding AllFiles}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock Margin="5,2" Text="{Binding }" />
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </Border>
                        </Expander>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</UserControl>
